import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { typeOrmConfig } from './config/database.config';
import { UserModule } from './modules/user/user.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TestService } from './test.service';
import { AuthModule } from './modules/auth/auth.module';
import { BookModule } from './modules/book/book.module';
import { MenuModule } from './modules/menu/menu.module';
import { OssModule } from './modules/oss/oss.module';
import { RoleModule } from './modules/role/role.module';
import { PermissionModule } from './modules/permission/permission.module';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal:true,envFilePath: '.env', }), // 全局加载环境变量
    TypeOrmModule.forRootAsync({
      imports:[ConfigModule],
      useFactory:typeOrmConfig, 
      inject:[ConfigService],
    }), // 加载数据库配置
    // 其他模块
    UserModule, 
    RoleModule, 
    AuthModule,
    BookModule,
    MenuModule,
    PermissionModule,
    OssModule
  ],
  controllers: [AppController],
  providers: [AppService,TestService], // 接收所有的service文件
})
export class AppModule {}
